package com.spring.basetype.web.service.impl;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import jxl.*;
import net.sf.ehcache.store.MemoryStore;

import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import sun.misc.BASE64Decoder;

import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.ObjectMetadata;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.oa.api.web.dao.OaMapper;
import com.spera.aliyunContent.AliyunContent;
import com.spera.aliyunUtil.CreateOSSClient;
import com.spera.aliyunUtil.SperaOSSUtil;
//import com.spera.genutil.TokenUtil;
import com.spera.shopoa.util.ObjectUtils;
import com.spera.shopoa.util.ShopOaSessionUtil;
import com.spera.shopoa.util.ShopOaSessionUtil.OaUser;
import com.spring.basetype.web.dao.BaseTypeMapper;
import com.spring.basetype.web.model.BaseType;
import com.spring.basetype.web.model.BaseTypeCode;
import com.spring.basetype.web.service.BaseTypeService;
import com.spring.oaassist.web.controller.BusinessController;
import com.spring.oaassist.web.dao.OaAssistMapper;
import com.spring.oaassist.web.model.Custom;
import com.spring.oaassist.web.requestModel.CourseTextbook;
import com.spring.oaassist.web.requestModel.RequestUser;
import com.spring.oaassist.web.service.OaAssistService;
import com.spring.oaassist.web.service.ReportService;
import com.spring.security.core.util.ApplicationUtils;
import com.spring.security.core.util.UDate;
import com.spring.security.core.util.UpdateMap;
import com.spring.security.web.dao.CommonMapper;
import com.spring.security.web.dao.JedisCache;
import com.spring.security.web.model.BaseResult;
import com.spring.tools.MyTools;
import com.sso.api.web.dao.SsoMapper;
import com.sso.api.web.model.Family;
import com.sso.api.web.model.MemberCard;
import com.sso.api.web.model.MemberInfo;
import com.sso.api.web.model.Users;

@Service
public class BaseTypeServiceImpl implements BaseTypeService {
    @Resource
    private BaseTypeMapper baseTypeMapper;    

    @Resource
	private SsoMapper ssoMapper;
    
	@Resource
	private JedisCache jedisCache;


	@Override
	public List<Map<String, Object>> getBaseTypeList(Map<String, Object> parm) {
		return baseTypeMapper.getBaseTypeList(parm);
	}
	
	@Override
	public BaseResult saveOrUpdateBaseType(BaseType bt) throws Exception {		
		int effect=0;
		
		if(MyTools.checkIsNull(bt.getId())){
			effect=baseTypeMapper.saveBaseType(bt);
		}else{
			baseTypeMapper.updateBaseTypeCodeByType(bt);
			effect=baseTypeMapper.updateBaseType(bt);			
		}		
	
		if(effect>0){
			return new BaseResult("1","更新成功");
		}		
		return new BaseResult("0","更新失败");
	}
	
	@Override
	public BaseResult deleteBaseType(String type) throws Exception {
		
		int effect=baseTypeMapper.deleteCode(type);
		int effect2=baseTypeMapper.deleteType(type);

		if(effect2>0){
			return new BaseResult("1","更新成功");
		}		
		return new BaseResult("0","更新失败");
	}
	
	@Override
	public List<BaseTypeCode> getBaseTypeCodeList(String type) throws Exception {		
		return baseTypeMapper.getBaseTypeCodeList(type);
	}

	@Override
	public BaseResult saveOrUpdateBaseTypeCode(BaseTypeCode btc) throws Exception {		
		int effect=0;
		
		if(MyTools.checkIsNull(btc.getId())){
			effect=baseTypeMapper.saveBaseTypeCode(btc);
		}else{
			effect=baseTypeMapper.saveBaseTypeCode(btc);
		}		
	
		if(effect>0){
			return new BaseResult("1","更新成功");
		}		
		return new BaseResult("0","更新失败");
	}

	@Override
	public BaseResult deleteCodeByID(String id) throws Exception {		
		int effect=baseTypeMapper.deleteCodeByID(id);

		if(effect>0){
			return new BaseResult("1","删除成功");
		}		
		return new BaseResult("0","删除失败");
	}
}
